package com.easysoft.framework.casereply.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.casereply.mapper.SysCaseReplyMapperExtd;
import com.easysoft.framework.casereply.model.SysCaseReply;
import com.easysoft.framework.casereply.model.SysCaseReplyQuery;
import com.easysoft.framework.casereply.model.SysCaseReplyView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by try on 2017/8/22.
 */
@Service("service.SysCaseReplyService")
public class SysCaseReplyService {

    @Autowired
    @Qualifier("mapper.SysCaseReplyMapperExtd")
    private SysCaseReplyMapperExtd sysCaseReplyMapperExtd;

    @DataSource(DataSource.MASTER)
    public int addSysCaseReply(SysCaseReply sysCaseReply){
        sysCaseReply.setId(UUIDUtils.getUUID());
        sysCaseReply.setCreateTime(new Date());
        return sysCaseReplyMapperExtd.insertSelective(sysCaseReply);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysCaseReply(String id){
        return sysCaseReplyMapperExtd.deleteByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysCaseReply(SysCaseReply sysCaseReply){
        return sysCaseReplyMapperExtd.updateByPrimaryKeySelective(sysCaseReply);
    }

    public SysCaseReply selectSysCaseReplyById(String id){
        return sysCaseReplyMapperExtd.selectByPrimaryKey(id);
    }

    @DataSource(DataSource.SLAVE)
    public List<SysCaseReplyView> selectSysCaseReplyListByPage(SysCaseReplyQuery query, Page page){
        int maxRow = sysCaseReplyMapperExtd.selectCountSysCaseReply(query);
        page.setMaxRow(maxRow);

        if (maxRow == 0) {
            return new ArrayList<SysCaseReplyView>();
        }

        return sysCaseReplyMapperExtd.selectSysCaseReplyListByPage(query,page);
    }
}
